<template>
  <div>
    <criteria-paged :model="model" pager='false' v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:criteria>
        <div novalidate class="form-inline" partial>
          <div class="form-group">
            <label for="c_plan_year">年份：</label>
            <v-select id="c_plan_year" :value.sync="$parent.$parent.model.c_plan_year"
            :options='$parent.$parent.c_year_list' close-on-select clear-button></v-select>
            <label for="c_plan_month">月份：</label>
            <v-select id="c_plan_month" :value.sync="$parent.$parent.model.c_plan_month"
            :options='$parent.$parent.c_month_list' close-on-select clear-button></v-select>
            <button type="button" class="btn btn-success width-80" @click="search()">
               <span class="glyphicon glyphicon-search"></span> 查询
            </button>
          </div>
          <div class="form-group">
            安检员:
            <chooser :userid.sync='$parent.$parent.loginer.id' resource-type="user"
            :width='300' :select-data.sync='$parent.$parent.model.chosenOrg'></chooser>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>用户名</th>
            <th>小区名称</th>
            <th>地址</th>
            <th>标记</th>
          </tr>
        </template>
        <template partial='body'>
          <td>{{$index+1}}</td>
          <td>{{row.f_user_name}}</td>
          <td>{{row.f_residential_area}}</td>
          <td>{{row.f_address}}</td>
          <td>{{row.sign=='1'?'◆':''}}</td>
        </template>
        <template partial="foot">
          <span>共{{ model.count }}项</span>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import Vue from 'vue'
import * as Util from '../Util'

export default {
  title: '安检员A',
  data () {
    let options = []
    let year = (new Date()).getFullYear()
    for(let i = year - 8; i <= year +1; i++ )
      options.push({label: i+'', value: i+''})
    let moptions = []
    for(let i=1; i<=12; i++)
      moptions.push({label: i + '', value: i + ''})
    let model = new PagedList('rs/sql/根据年月安检员查询安检项', 3000,
    {f_subcompany: 'this.f_subcompany', f_plan_year: 'this.c_plan_year[0]', f_plan_month: 'this.c_plan_month[0]', f_checker_id: 'this.chosenOrg.id'})
    model.c_plan_year = [year+'']
    model.c_plan_month = [moptions[new Date().getMonth()].value]
    model.chosenOrg = {id:0}
    return {
      model: model,
      c_year_list: options,
      c_month_list: moptions,
      loginer: Util.f
    }
  },
  watch: {
      'model.c_plan_year' (val) {
        this.$parent.$refs.right.$refs.paged.$refs.criteria.model.f_plan_year = val[0]
      },
      'model.c_plan_month' (val) {
        this.$parent.$refs.right.$refs.paged.$refs.criteria.model.f_plan_month = val[0]
      }
  },
  ready () {
    this.model.id = this.$parent.loginer.id
    this.model.chosenOrg.id = this.$parent.loginer.parent.id
    this.model.f_subcompany = Vue.f_subcompany
  },
  computed: {
    selected () {
      return this.$refs.paged.$refs.grid.selected
    }
  }
}
</script>
